<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

$tabs=array(
	array('op'=>'list','title'=>'佣金列表'),
);
$install = check_account_permission('jy_commission');
if(!$install){
	exi('请联系管理员开启<微客分销>！','error');
}
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['ordersn']){
		$params['ordersn']=$_RQ['ordersn'];
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 20;
	$total='';
	$list=pdo_getslice('jy_commission_commission',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array(
			'tip'=>'只有是代理商的，才能分配到佣金！有些代理商就算有下级，如果被关闭了也是不能获得佣金的，请知悉！',
			'data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'分销商','type'=>'member'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'money','title'=>'佣金','type'=>'string'),
			array('name'=>'level','title'=>'佣金类型','type'=>'radio','options'=>'commission_money_types'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
			array('name'=>'status','title'=>'佣金状态','type'=>'radio','options'=>'commission_status'),
			array('name'=>'complete_time','title'=>'订单完成时间','type'=>'time'),
			array('name'=>'balancesn','title'=>'结算单号','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'detail','title'=>'佣金详情'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'name'=>'ordersn','title'=>'订单号'),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
			array('type'=>'radio','width'=>15,'name'=>'status','title'=>'佣金状态','options'=>'commission_status'),
		),
	);
	$return['htmls']=$htmls;
	$return['commission_status']=$this->commission_status;
	$return['commission_money_types']=$this->commission_money_types;
	exi($return);
}
if($_RQ['op']=='detail'){
	$item=pdo_get('jy_commission_commission',array('id'=>intval($_RQ['id'])),array('id','remark'));
	if(!$item){
		exi('指定佣金不存在！','error');
	}
	$item['remark']=model('jy_commission/commission')->commission_remark($item['remark']);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'佣金明细',
		'look'=>array(
			array('type'=>'text','name'=>'remark','title'=>'佣金明细'),
		),
	);
	exi($return);
}